home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 19
/
Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso
/
Aminet
/
comm
/
maxs
/
dfbv13.lha
/
dfb
/
Developers
/
dfbaddfile.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-02
|
3KB
|
116 lines
/* DFBAddFile - by A.Leppard - 5/7/96
This demo source code is in the public domain.
This is one of the series of dfb dos commands, this command adds a file
to the file base. Use:
dfbaddfile <filename> <description> <section> <uploader> [<alias>]
e.g:
dfbaddfile ram:cdn-new.lha "a new demo" 23 sysop */
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <strings.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <dos/dos.h>
#include <dos/dostags.h>
#include "dfb_pragmas.h"
#include "dfb_protos.h"
#include "dfb.h"
int FileSize(char *filename)
{
BPTR file;
int len;
struct FileInfoBlock *fib;
len=-1;
if(file=Open(filename, MODE_OLDFILE) ) {
if(fib=AllocDosObjectTags(DOS_FIB, ADO_FH_Mode)) {
len = ExamineFH(file, fib) ? fib->fib_Size : -1;
FreeDosObject(DOS_FIB, fib);
}
Close(file);
}
return(len);
}
/* Returns pointer to file name from path & file name */
char *StripPath(char *source)
{
char *last;
last=source-1;
while(*source!='\0') {
if(*source==':' || *source=='/')
last=source;
source++;
}
return(last+1);
}
main(int argv, char **argc)
{
struct Library *DfbBase;
struct dfbFile *File, *FileExist, dfbfile;
struct dfbFileBase *FileBase;
File=&dfbfile;
if(argv==5 || argv==6) {
if(DfbBase=OpenLibrary("dfb.library",0)) {
if(FileBase=OpenFileBase(ATSTART)) { /* AddFile needs file base open */
File->fb_FileSize=FileSize(argc[1]);
if(File->fb_FileSize!=-1) {
FixTime(File); /* time/date of upload is now */
File->fb_Section=atoi(argc[3]);
File->fb_Name=StripPath(argc[1]);
/* get file name from path */
/* Is the file already in the file base ? */
FileExist=FindFile(0, NULL, File->fb_Name);
if(!FileExist) { /* if it isn't add it... */
File->fb_Desc=argc[2];
File->fb_Uploader=argc[4];
if(argv==6)File->fb_Alias=argc[5];
else
File->fb_Alias=NULL;
File->fb_Status=0;
File->fb_Down=0;
if(AddFile(FileBase, File))
printf("Can't write to file base, file not added: %s.\n", argc[1]);
else
printf("Added File: %s\n", argc[1]);
}
else { /* free FindFile file node */
printf("Can't add file, file already in file base: %s\n", argc[1]);
FreeMem((char *)FileExist, FileExist->fb_Length);
}
}
else
printf("Can't open file, file not added: %s\n", argc[1]);
CloseFileBase(FileBase);
}
else
printf("Can't load file base, file not added: %s\n", argc[1]);
CloseLibrary(DfbBase);
}
else
printf("Can't load dfb.library, file not added: %s\n", argc[1]);
}
else {
printf("DFBAddFile, use: DFBAddFile <filename> <description> <section>\n");
printf("<uploader> [<alias>], e.g:\n");
printf("dfbaddfile ram:cdn-new.lha \"latest demo\" 23 Sysop\n");
}
}